#include "cjson/cjson.h"
#include "log/log.h"    
int main(void)
{
    //生成json字符串 
    char *name = "zhangsan";
    int age = 18;
    //创建一个空的CJSON对象
    cJSON *root = cJSON_CreateObject();
    //向对象中添加键值对
    cJSON_AddStringToObject(root, "name", name);
    cJSON_AddNumberToObject(root, "age", age);
    //将CJSON对象转换为字符串
    char *json_str = cJSON_Print(root);
    log_debug("%s\n", json_str);
    //2.解析json字符串
    cJSON *json = cJSON_Parse(json_str);
    cJSON *name_obj = cJSON_GetObjectItem(json, "name");
    cJSON *age_obj = cJSON_GetObjectItem(json, "age");
    if (name_obj == NULL && age_obj == NULL)
    {
        log_debug("解析失败\n");
        return -1;
    }
    char * name1 = name_obj->valuestring;
    int age1 = age_obj->valueint;
    log_debug("name:%s,age:%d\n", name1, age1);
    return 0;
}